package com.chen.servicemap.remote;

import com.chen.internalcommon.constant.MapConfigConstants;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

/**
 * @author chenLiuPing
 **/
@Slf4j
@Service
public class MapDicDistrictlClient {
    @Value(("${map.key}"))
    private String mapKey;

    @Autowired
    private RestTemplate restTemplate;

    public String dicDistrict(String keywords) {
        // https://restapi.amap.com/v3/config/district?keywords=北京&subdistrict=2&key=<用户的key>
        // 拼装请求的url
        StringBuilder url = new StringBuilder(MapConfigConstants.DISTRICT_URL);
        url.append("?keywords=").append(keywords)
                .append("&subdistrict=3")
                .append("&key=").append(mapKey);
        log.info("url:{}", url);

        // 请求
        ResponseEntity<String> forEntity = restTemplate.getForEntity(url.toString(), String.class);
        return forEntity.getBody();

    }
}
